package com.qy.mybatisplus.mapper;

import com.qy.mybatisplus.entity.User;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author qy
 * @since 2019-12-10
 */
@Repository
public interface UserMapper extends BaseMapper<User> {


    @Select("select * from `test` where `id` = #{id} for update")
    @Results({
            @Result(column = "id", property = "id", javaType = Long.class),
            @Result(column = "count", property = "count", javaType = Integer.class),
            @Result(column = "version", property = "version", javaType = Integer.class)
    })
    User getById(@Param("id") Long id);


    @Update("update `test` set `count` = #{count}, `version` = #{version} + 1 where `id` = #{id} and `version` = #{version}")
    int update(User user);

    @Update("update `test` set `count` = #{count} where `id` = #{id}")
    Boolean updateNoSafe(User user);
}
